﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace TaskDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("1");

            var task = Test();
            int b = 1;
            Console.WriteLine("4");
            Thread.Sleep(1000);

            Console.WriteLine("5");

            task.Wait();
            Console.WriteLine("7");
            Console.ReadKey();
        }

        static async Task Test()
        {
            //主线程
            Console.WriteLine("2");
            //主线程
            await GetName();

            Console.WriteLine("6");
        }

        static async Task GetName()
        {
            Console.WriteLine("3");

            ///开新线程
            await Task.Run(() =>
            {
                Thread.Sleep(1000 * 5);
                Console.WriteLine("5 new");
            });
            await Task.Run(() =>
            {
                Thread.Sleep(1000 * 5);
                Console.WriteLine("5 news");
            });
        }
    }
}
